<template>
    <div>
     <h1>房价信息录入</h1>
     <table class="table">
        <thead>
           
             <tr>
                <td>房型名称</td>
                <td>
                     <select v-model="data.roomTypeId">
                        <option value="0">请选择</option>
                        <option v-for="c in qwery" :value="c.roomTypeId">{{ c.name }}</option>
                     </select>
                </td>
            </tr>
             <tr>
                <td>产品名称</td>
                <td>
                     <input type="text" v-model="data.name">
                </td>
            </tr>
             <tr>
                <td>电话</td>
                <td>
                     <input type="text" v-model="data.phone">
                </td>
            </tr>
             <tr>
                <td>价格</td>
                <td>
                     <input type="text" v-model="data.price">
                </td>
            </tr>
             <tr>
                <td>状态</td>
                <td>
                    <input type="radio" name="start" id="" v-model="data.start" value="1">预定付费
                     <input type="radio" name="start" id="" v-model="data.start" value="2">到店付费
                </td>
            </tr>
              <tr>
                <td>地址</td>
                <td>
                     <input type="text" v-model="data.addr">
                </td>
            </tr>
             <tr>
              
                <td colspan="2">
                    <input type="button" value="添加" @click="Add">
                </td>
            </tr>
        </thead>
     </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios";
import { useRouter } from "vue-router";
const router=useRouter()
onMounted(()=>{

    Xialak();
})
const data=ref({
    "id": 0,
  "roomTypeId": 0,
  "name": "",
  "phone": "",
  "price": 0,
  "start": 0,
  "addr": ""
})
const Add=()=>{
    axios.post("https://localhost:7162/api/RoomPrice/AddRoomPrice",data.value).then(res=>{
     
        if(res.data>0){
            alert('添加成功');
            router.push("/ShowPriceView");
        }
        else{
            alert('添加失败');
        }
    })
}

const qwery=ref([{
     "roomTypeId": 1,
    "name": "单人房"
}])
const Xialak=()=>{
    axios.get("https://localhost:7162/api/RoomModel/Xialak").then(res=>{
        qwery.value=res.data
    })
}
</script>

<style scoped>

</style>